import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home/Home.vue'
import store from '../store'
Vue.use(VueRouter)

const routes = [{
        path: '/',
        redirect: '/home'
    },
    {
        path: '/home',
        name: 'Home',
        component: Home
    },
    {
        path: '/sort',
        name: 'Sort',
        //路由懒加载
        component: () =>
            import ('../views/sort/sort.vue'),


    },
    {
        path: '/category',
        name: 'Category',
        component: () => {
            return import ('../views/category.vue')
        }
    }, {
        path: '/product-detail/:id',
        name: 'Product-detail',
        component: () =>
            import ('../views/product-detail.vue')
    }, {
        path: '/shop',
        name: 'Shop',
        component: () =>
            import ('../views/shop.vue')
    },
    {
        path: '/mime',
        name: 'mime',
        component: () =>
            import ('../views/mime/mime.vue')
    }, {
        path: '/login',
        name: 'Login',
        component: () =>
            import ('../views/login.vue')
    },
    {
        path: '/proxy',
        name: 'Proxy',
        component: () =>
            import ('../views/proxy.vue')
    }

]

const router = new VueRouter({
    mode: 'history',
    routes,

})
router.beforeEach(function(to, from, next) {

    if (to.path == '/mime' && !store.state.islogin) {
        next('/login')

    } else if (to.path == '/shop' && !store.state.islogin) {
        next('/login')
    } else next()


})

export default router